
use entropy_bible, clear
merge m:1 trans using data_bible_final, keep(3)


gen booktitle=""                                                             
replace booktitle="Matthew"  if book==40                  
replace booktitle="Mark"  if book==41                     
replace booktitle="Luke"  if book==42                     
replace booktitle="John"  if book==43                     
replace booktitle="Acts"  if book==44                              
replace booktitle="Revelation" if book==66                
ren booktitle Book

/* replace Koine Greek */
replace language="Koine Greek" if trans=="ell-x-bible-koine1894"



keep if chars_original>=10000
bysort book: gen howmany2=_N
drop if howmany2<100


local combiner
local books 44 43 42 41 40 66
foreach book of local books {
preserve
keep if book==`book'
local title=Book[1]
collapse (mean) D*, by(language ISO) fast
gen label="esk" if language=="Northwest Alaska Inupiatun" 			
replace label="cmn" 		if language=="Mandarin Chinese"
replace label="deu" 			if language=="Standard German"
replace label="vie" 	if language=="Vietnamese"
replace label="chr" 		if language=="Cherokee"
replace label="eng" 		if language=="English"
replace label="mya" 		if language=="Burmese"
replace label="tam" 			if language=="Tamil"
replace label="grc" if language=="Koine Greek"
replace label="qvw" 		if language=="Huaylla Wanca Quechua"
replace label="xuo" 				if language=="Kuo"
replace label="zul" 				if language=="Zulu"
spearman D_order D_structure
local rho: di %3.2f r(rho)
gen reciprocal=1/D_order

*scatter D_structure rec

reg D_structure rec
predict pred_reg
local r2_1: di %3.2f (e(r2))
mat define mat=e(b)
local b0: di %3.2f mat[1,2]
local b1: di %3.2f mat[1,1]
local N: di %5.0fc e(N)


tw (scatter D_structure D_order, msymbol(Oh) msize(small) mcolor(gs8)) ///
 (scatter D_s D_or if label!="",  mlabangle(45) msize(medlarge)  msymbol(o) mcolor(orange) mlabcolor(orange) mlab(label) mlabsize(medlarge) msize(small)) ///
  (line pred_reg D_order, lpattern(dash) lcolor(black) lwidth(thick) sort) /// 
 , legend(position(7) symxsize(2) keygap(0) region(lcolor(white))  cols(1) order(1 3) label(3 "E(D{subscript:s}|D{subscript:o}) = `b0'+`b1'*D{subscript:o}{superscript:-1}; R{superscript:2}=`r2_1'")  ///
 label(1 "r{subscript:s}= `rho' | N = `N'")) ///
 graphregion(color(white)) ///
 ylabel(minmax,format(%3.2f) nogrid) xlabel(minmax,format(%3.2f) nogrid) nodraw   ///
 title("`title'", size(vlarge)) ytitle("") xtitle("") yscale(nofextend) xscale(nofextend) saving(`book', replace)
restore
local combiner `"`combiner' `book'.gph"'
}

graph combine `combiner', ///
cols(2)  l1title("Word structure information") b1title("Word order information") ///
iscale(.60) xsize(1) ysize(1.8) scheme(s2mono) graphregion(color(white))


graph export fig1.png, height(10000) replace
exit
